package com.example.Spring.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component//组件层
@Aspect
public class AspectDemo {
//    @Around("execution(* com.example.Spring.controller.*.*(..))")
      @Pointcut("execution(* com.example.Spring.controller.*.*(..))")
      public void pt(){

      }
      @Around("pt()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        log.info("Around方法开始执行");
        Object proceed = pjp.proceed();
        log.info("Around方法结束执行");
        return proceed;
    }
    @Before("pt()")
    public void doBefore(){
        log.info("执行Before方法");
    }
//    @After("pt()")
    @After("execution(* com.example.Spring.controller.*.*(..))")
    public void doAfter(){
        log.info("执行After方法");
    }
    @AfterReturning("pt()")
//    @AfterReturning("execution(* com.example.Spring.controller.*.*(..))")
    public void doAfterReturning(){
        log.info("执行AfterReturning方法");
    }
    @AfterThrowing("pt()")
//    @AfterThrowing("execution(* com.example.Spring.controller.*.*(..))")
    public void doAfterThrowing(){
        log.info("执行AfterThrowing方法");
    }
}
